package com.flyoil.petromp.adapter.adapter_statics;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.flyoil.petromp.R;
import com.flyoil.petromp.base.MyBaseAdapter;
import com.flyoil.petromp.entity.entity_statics.StaticsSelectTypeEntity;

/**
 * Created by songzhiiyn on 2017/10/17.
 * 统计界面刷选条件的适配器
 */

public class ItemStaticSelectTypeAdapter extends MyBaseAdapter<StaticsSelectTypeEntity> {
    public ItemStaticSelectTypeAdapter(Context context) {
        super(context);
    }

    @Override
    public View setView(int position, View convertView, ViewGroup parent) {
        Viewhoder viewhoder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_staticstics_select_type_adapter, null);
            viewhoder = new Viewhoder(convertView);
            convertView.setTag(viewhoder);
        } else {
            viewhoder = (Viewhoder) convertView.getTag();
        }
        StaticsSelectTypeEntity entity = (StaticsSelectTypeEntity) getItem(position);
        if (entity.isSelect()) {
            viewhoder.tv_name.setTextColor(context.getResources().getColor(R.color.home_color));
            viewhoder.tv_name.setBackgroundResource(R.drawable.backgroud_shape_red_stroke);
        } else {
            viewhoder.tv_name.setTextColor(context.getResources().getColor(R.color.gry_4d4d));
            viewhoder.tv_name.setBackgroundResource(R.drawable.backgroud_shape_gray_stroke);
        }
        viewhoder.tv_name.setText(entity.getName());
        return convertView;
    }

    private class Viewhoder {
        private TextView tv_name;

        public Viewhoder(View view) {
            this.tv_name = view.findViewById(R.id.tv_item_staticstics_select_type_name);
        }
    }
}
